import { addComDao, delComDao, getComByIdsByPageDao, getComByPageDao, updateComDao } from "../Dao/commentDao.js"
import { findUserByIdDao } from "../Dao/userDao.js";

export const addComServ = async (obj)=>{
    await addComDao(obj);
    return {
        code:0,
        msg:"add OK"
    }
}

export const delComServ = async (id) => {
    await delComDao(id)
    return {
        code:0,
        msg:"del OK"
    }
}

export const updateComServ = async (id,obj)=>{
    await updateComDao(id,obj)
    return {
        code:0,
        msg:"update ok"
    }
}

export const getComByPageServ = async(page,size)=>{
    const data = await getComByPageDao(page,size);
    data.list = await Promise.all(data.list.map(async item=>{
        const obj = item.toObject();
        obj.user = await findUserByIdDao(obj.userId)
        return obj
    }))
    return {
        code:0,
        data
    }
}
export const getComByIdsPageServ = async(ids,page,size)=>{
    const data = await getComByIdsByPageDao(ids,page,size);
    data.list = await Promise.all(data.list.map(async item=>{
        const obj = item.toObject();
        obj.user = await findUserByIdDao(obj.userId)
        return obj
    }))
    return {
        code:0,
        data
    }
}